package czy.demo.controller;

import czy.demo.pojo.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/template")
public class TemplateController {

    private static final Logger logger = LoggerFactory.getLogger(TemplateController.class);

    @Autowired
    private MongoTemplate template;

    @GetMapping("/all")
    public List<Person> findAll(){
        return this.template.findAll(Person.class);
    }

    @GetMapping("/get/{id}")
    public Person findById(@PathVariable Integer id){
        return this.template.findById(id,Person.class);
    }

    @PostMapping("/create")
    public Person insert(@RequestBody Person person){
        this.template.insert(person);
        return person;
    }

    @PutMapping("/update")
    public Person update(@RequestBody Person person){
        this.template.save(person);
        return person;
    }

    @DeleteMapping("/delete/{id}")
    public Person delete(@PathVariable Integer id){
        return null;
    }



}
